<template>
	<view>
		<city-select v-model="cityList" :formatName="formatName" :activeCity="activeCity" :hotCity="hotCity" :obtainCitys="obtainCitys"
		 :isSearch="true" ref="citys"  @cityClick="cityClick" ></city-select>
	</view>
	<!-- </view> -->
</template>

<script>
	import citys from '../../../common/citys.js'
	//console.log(citys.length)
	import citySelect from '@/components/city-select/city-select.vue'
	export default {
		components: {
			citySelect
		},
		data() {
			return {
				//需要构建索引参数的名称（注意：传递的对象里面必须要有这个名称的参数）
				formatName: 'title',
				//当前城市
				activeCity: {
					cityName: '北京',
					cityCode: 110000
				},
				//热门城市
				hotCity: [

				],
				//显示的城市数据
				obtainCitys: [

				],
				cityList: [],
				currcoude:''
			}
		},
		onLoad(options) {
			//动态更新数据
			//修改数据格式
			this.formatName = 'cityName'
			//修改当前城市
			this.activeCity = {
				cityName: '上海',
				cityCode: 310000
			}
			//修改热门城市
			this.hotCity = [{
					cityName: '全国',
					cityCode: ''
				},
				{
					cityName: '北京',
					cityCode: 110000
				},
				{
					cityName: '深圳',
					cityCode: 440300
				},
				{
					cityName: '广州',
					cityCode: 440100
				},
				{
					cityName: '上海',
					cityCode: 310000
				}
			]
			//修改构建索引数据
			this.obtainCitys = citys
			uni.showToast({
				icon: 'none',
				title: '更新数据成功',
				// #ifdef MP-WEIXIN
				duration: 1000,
				// #endif
				mask: true
			})
			var cityName = this.cityName;
			if (cityName != '' && cityName != undefined) {
				var cityarr = cityName.split(',');
				this.cityList = cityarr;
				console.log(this.cityList);
			}
			
			console.log(options);
			if(options.cityCode!=''){
				console.log(options.cityCode);
				//this.currentCode=options.cityCode;
			}
			

			// #ifdef APP-PLUS
			this.getlocation();
			// #endif 

		},
		methods: {
			cityClick(item) {
				console.log("fuceng--" + JSON.stringify(item))
				var pages = getCurrentPages();
				var prevPage = pages[pages.length - 2]; //上一个页面
				prevPage.city = item;
				uni.navigateBack();
			},
			getlocation() {
				var that = this;
				uni.getLocation({
					type: 'wgs84',
					geocode: true,
					success: function(res) {
						if (res.address != undefined) {
							that.activeCity.cityCode = res.address.cityCode;
							that.activeCity.cityName = res.address.city;
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	@import "@/static/css/list.scss";

	page {
		background-color: #f5f5f5;
	}

	.city-top {
		margin-top: 20rpx;
	}

	.input-view {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: center;
		background-color: #fff;
		padding: 20rpx 15px;
		flex-wrap: nowrap;
		width: 85%;
		border-radius: 10rpx;
		margin: 0rpx auto;
	}

	.nav-bar-input {
		/* #ifdef APP-PLUS-NVUE */
		/* #endif */
		padding: 0 5px;
		font-size: 28rpx;
		background-color: #fff;
		color: #333;
		flex: 1;
	}

	.section {
		padding: 0 30rpx;
		display: flex;
		flex-direction: column;
		width: 100%;
		font-size: 30rpx;
		color: #333333;
		line-height: 70rpx;
		height: 70rpx;
	}

	.Location-current {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding: 20rpx 30rpx;
		background-color: #FFFFFF;
		align-items: center;

		.Location-current-title {
			font-size: 28rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
		}

		.Location-current-Refresh {
			font-size: 28rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			color: #3f74f8;
			margin-right: 40rpx;
		}
	}

	.label-2-text {
		font-size: 28rpx;
		color: #666666;
	}

	.uni-list::before,
	.uni-list::after {
		height: 0;
	}
</style>
